{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import numpy as np\n",
    "import torch\n",
    "from mpl_toolkits import mplot3d\n",
    "from d2l import torch as d2l"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 11.2.1.2. 凸函数"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "data": {
      "text/plain": "<Figure size 900x300 with 3 Axes>",
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"539.503125pt\" height=\"197.398125pt\" viewBox=\"0 0 539.503125 197.398125\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n   <cc:Work>\n    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n    <dc:date>2024-07-15T16:49:16.775813</dc:date>\n    <dc:format>image/svg+xml</dc:format>\n    <dc:creator>\n     <cc:Agent>\n      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n     </cc:Agent>\n    </dc:creator>\n   </cc:Work>\n  </rdf:RDF>\n </metadata>\n <defs>\n  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n  <g id=\"patch_1\">\n   <path d=\"M 0 197.398125 \nL 539.503125 197.398125 \nL 539.503125 0 \nL 0 0 \nz\n\" style=\"fill: #ffffff\"/>\n  </g>\n  <g id=\"axes_1\">\n   <g id=\"patch_2\">\n    <path d=\"M 30.103125 173.52 \nL 177.809007 173.52 \nL 177.809007 7.2 \nL 30.103125 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g id=\"matplotlib.axis_1\">\n    <g id=\"xtick_1\">\n     <g id=\"line2d_1\">\n      <path d=\"M 36.817029 173.52 \nL 36.817029 7.2 \n\" clip-path=\"url(#pba43b88faf)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_2\">\n      <defs>\n       <path id=\"m45064b488f\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m45064b488f\" x=\"36.817029\" y=\"173.52\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- −2 -->\n      <g transform=\"translate(29.445935 188.118438)scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \nL 4684 2272 \nL 4684 1741 \nL 678 1741 \nL 678 2272 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-32\" x=\"83.789062\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_3\">\n      <path d=\"M 104.124334 173.52 \nL 104.124334 7.2 \n\" clip-path=\"url(#pba43b88faf)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_4\">\n      <g>\n       <use xlink:href=\"#m45064b488f\" x=\"104.124334\" y=\"173.52\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- 0 -->\n      <g transform=\"translate(100.943084 188.118438)scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_5\">\n      <path d=\"M 171.43164 173.52 \nL 171.43164 7.2 \n\" clip-path=\"url(#pba43b88faf)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#m45064b488f\" x=\"171.43164\" y=\"173.52\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 2 -->\n      <g transform=\"translate(168.25039 188.118438)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-32\"/>\n      </g>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_7\">\n      <path d=\"M 30.103125 165.96 \nL 177.809007 165.96 \n\" clip-path=\"url(#pba43b88faf)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_8\">\n      <defs>\n       <path id=\"m43b016f915\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m43b016f915\" x=\"30.103125\" y=\"165.96\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- 0.0 -->\n      <g transform=\"translate(7.2 169.759219)scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \nL 1344 794 \nL 1344 0 \nL 684 0 \nL 684 794 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_9\">\n      <path d=\"M 30.103125 128.16 \nL 177.809007 128.16 \n\" clip-path=\"url(#pba43b88faf)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_10\">\n      <g>\n       <use xlink:href=\"#m43b016f915\" x=\"30.103125\" y=\"128.16\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_5\">\n      <!-- 0.5 -->\n      <g transform=\"translate(7.2 131.959219)scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n       <use xlink:href=\"#DejaVuSans-35\" x=\"95.410156\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_11\">\n      <path d=\"M 30.103125 90.36 \nL 177.809007 90.36 \n\" clip-path=\"url(#pba43b88faf)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_12\">\n      <g>\n       <use xlink:href=\"#m43b016f915\" x=\"30.103125\" y=\"90.36\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_6\">\n      <!-- 1.0 -->\n      <g transform=\"translate(7.2 94.159219)scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_4\">\n     <g id=\"line2d_13\">\n      <path d=\"M 30.103125 52.56 \nL 177.809007 52.56 \n\" clip-path=\"url(#pba43b88faf)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_14\">\n      <g>\n       <use xlink:href=\"#m43b016f915\" x=\"30.103125\" y=\"52.56\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- 1.5 -->\n      <g transform=\"translate(7.2 56.359219)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n       <use xlink:href=\"#DejaVuSans-35\" x=\"95.410156\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_5\">\n     <g id=\"line2d_15\">\n      <path d=\"M 30.103125 14.76 \nL 177.809007 14.76 \n\" clip-path=\"url(#pba43b88faf)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_16\">\n      <g>\n       <use xlink:href=\"#m43b016f915\" x=\"30.103125\" y=\"14.76\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 2.0 -->\n      <g transform=\"translate(7.2 18.559219)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-32\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n      </g>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_17\">\n    <path d=\"M 36.817029 14.76 \nL 40.855467 32.359681 \nL 44.55737 47.53638 \nL 48.259272 61.798321 \nL 51.96117 75.145494 \nL 55.32654 86.48551 \nL 58.691902 97.069496 \nL 62.057268 106.8975 \nL 65.086094 115.096311 \nL 68.114924 122.682777 \nL 71.143756 129.656883 \nL 73.836048 135.342002 \nL 76.528339 140.54328 \nL 79.220631 145.260719 \nL 81.912923 149.494318 \nL 84.26868 152.801821 \nL 86.624435 155.73888 \nL 88.980191 158.305501 \nL 90.999409 160.21062 \nL 93.018628 161.84358 \nL 95.037849 163.20438 \nL 97.057067 164.29302 \nL 99.076287 165.1095 \nL 101.095506 165.65382 \nL 102.778188 165.89952 \nL 104.460871 165.95622 \nL 106.143553 165.82392 \nL 107.826236 165.50262 \nL 109.845455 164.86758 \nL 111.864674 163.96038 \nL 113.883893 162.78102 \nL 115.903113 161.3295 \nL 117.922332 159.60582 \nL 119.941551 157.60998 \nL 122.297305 154.937522 \nL 124.653063 151.894619 \nL 127.008818 148.481279 \nL 129.364574 144.6975 \nL 132.056866 139.91958 \nL 134.749157 134.657821 \nL 137.441449 128.912223 \nL 140.13374 122.682786 \nL 143.16257 115.096324 \nL 146.1914 106.8975 \nL 149.220226 98.086327 \nL 152.585596 87.577918 \nL 155.950958 76.313523 \nL 159.316324 64.29312 \nL 163.018227 50.1975 \nL 166.720129 35.187121 \nL 170.422027 19.261993 \nL 171.095104 16.268222 \nL 171.095104 16.268222 \n\" clip-path=\"url(#pba43b88faf)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"line2d_18\">\n    <path d=\"M 53.643855 80.91 \nL 137.777987 128.16 \n\" clip-path=\"url(#pba43b88faf)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 30.103125 173.52 \nL 30.103125 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_4\">\n    <path d=\"M 177.809007 173.52 \nL 177.809007 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_5\">\n    <path d=\"M 30.103125 173.52 \nL 177.809007 173.52 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_6\">\n    <path d=\"M 30.103125 7.2 \nL 177.809007 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_2\">\n   <g id=\"patch_7\">\n    <path d=\"M 207.350184 173.52 \nL 355.056066 173.52 \nL 355.056066 7.2 \nL 207.350184 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g id=\"matplotlib.axis_3\">\n    <g id=\"xtick_4\">\n     <g id=\"line2d_19\">\n      <path d=\"M 214.064088 173.52 \nL 214.064088 7.2 \n\" clip-path=\"url(#pc5d08e8c14)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_20\">\n      <g>\n       <use xlink:href=\"#m45064b488f\" x=\"214.064088\" y=\"173.52\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_9\">\n      <!-- −2 -->\n      <g transform=\"translate(206.692994 188.118438)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-32\" x=\"83.789062\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_5\">\n     <g id=\"line2d_21\">\n      <path d=\"M 281.371393 173.52 \nL 281.371393 7.2 \n\" clip-path=\"url(#pc5d08e8c14)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_22\">\n      <g>\n       <use xlink:href=\"#m45064b488f\" x=\"281.371393\" y=\"173.52\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_10\">\n      <!-- 0 -->\n      <g transform=\"translate(278.190143 188.118438)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_6\">\n     <g id=\"line2d_23\">\n      <path d=\"M 348.678699 173.52 \nL 348.678699 7.2 \n\" clip-path=\"url(#pc5d08e8c14)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_24\">\n      <g>\n       <use xlink:href=\"#m45064b488f\" x=\"348.678699\" y=\"173.52\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_11\">\n      <!-- 2 -->\n      <g transform=\"translate(345.497449 188.118438)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-32\"/>\n      </g>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_4\">\n    <g id=\"ytick_6\">\n     <g id=\"line2d_25\">\n      <path d=\"M 207.350184 165.96 \nL 355.056066 165.96 \n\" clip-path=\"url(#pc5d08e8c14)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_26\">\n      <g>\n       <use xlink:href=\"#m43b016f915\" x=\"207.350184\" y=\"165.96\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_12\">\n      <!-- −1.0 -->\n      <g transform=\"translate(176.067371 169.759219)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-31\" x=\"83.789062\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" x=\"147.412109\"/>\n       <use xlink:href=\"#DejaVuSans-30\" x=\"179.199219\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_7\">\n     <g id=\"line2d_27\">\n      <path d=\"M 207.350184 128.16 \nL 355.056066 128.16 \n\" clip-path=\"url(#pc5d08e8c14)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_28\">\n      <g>\n       <use xlink:href=\"#m43b016f915\" x=\"207.350184\" y=\"128.16\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_13\">\n      <!-- −0.5 -->\n      <g transform=\"translate(176.067371 131.959219)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-30\" x=\"83.789062\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" x=\"147.412109\"/>\n       <use xlink:href=\"#DejaVuSans-35\" x=\"179.199219\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_8\">\n     <g id=\"line2d_29\">\n      <path d=\"M 207.350184 90.36 \nL 355.056066 90.36 \n\" clip-path=\"url(#pc5d08e8c14)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_30\">\n      <g>\n       <use xlink:href=\"#m43b016f915\" x=\"207.350184\" y=\"90.36\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_14\">\n      <!-- 0.0 -->\n      <g transform=\"translate(184.447059 94.159219)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_9\">\n     <g id=\"line2d_31\">\n      <path d=\"M 207.350184 52.56 \nL 355.056066 52.56 \n\" clip-path=\"url(#pc5d08e8c14)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_32\">\n      <g>\n       <use xlink:href=\"#m43b016f915\" x=\"207.350184\" y=\"52.56\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_15\">\n      <!-- 0.5 -->\n      <g transform=\"translate(184.447059 56.359219)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n       <use xlink:href=\"#DejaVuSans-35\" x=\"95.410156\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_10\">\n     <g id=\"line2d_33\">\n      <path d=\"M 207.350184 14.76 \nL 355.056066 14.76 \n\" clip-path=\"url(#pc5d08e8c14)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_34\">\n      <g>\n       <use xlink:href=\"#m43b016f915\" x=\"207.350184\" y=\"14.76\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_16\">\n      <!-- 1.0 -->\n      <g transform=\"translate(184.447059 18.559219)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n      </g>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_35\">\n    <path d=\"M 214.064088 14.76 \nL 214.73716 14.909179 \nL 215.410232 15.356127 \nL 216.083305 16.099077 \nL 216.756381 17.135113 \nL 217.76599 19.229413 \nL 218.775598 21.955074 \nL 219.785207 25.287884 \nL 221.131352 30.624264 \nL 222.477501 36.90271 \nL 224.160182 45.923418 \nL 226.179403 58.171073 \nL 228.871693 76.193931 \nL 235.938961 124.681663 \nL 237.958182 136.69576 \nL 239.640863 145.470019 \nL 240.987008 151.521667 \nL 242.333153 156.608774 \nL 243.342766 159.742252 \nL 244.352374 162.25987 \nL 245.361983 164.139306 \nL 246.035059 165.02924 \nL 246.708132 165.624484 \nL 247.381204 165.922694 \nL 248.054279 165.922694 \nL 248.727351 165.624484 \nL 249.400423 165.02924 \nL 250.073496 164.139306 \nL 250.74657 162.958204 \nL 251.756179 160.651107 \nL 252.765787 157.720098 \nL 253.775398 154.191196 \nL 255.121543 148.610814 \nL 256.46769 142.111763 \nL 258.150371 132.853516 \nL 260.169592 120.384388 \nL 262.861884 102.186453 \nL 269.256078 58.171093 \nL 271.275298 45.923431 \nL 272.95798 36.902728 \nL 274.304126 30.624278 \nL 275.650272 25.287902 \nL 276.996418 20.977748 \nL 278.006028 18.460126 \nL 279.015637 16.580694 \nL 279.688711 15.69076 \nL 280.361784 15.095516 \nL 281.034857 14.797306 \nL 281.70793 14.797306 \nL 282.381003 15.095516 \nL 283.054076 15.69076 \nL 283.727149 16.580694 \nL 284.400222 17.761796 \nL 285.409831 20.068897 \nL 286.419441 22.999906 \nL 287.42905 26.528809 \nL 288.775197 32.109199 \nL 290.121343 38.608237 \nL 291.804026 47.866498 \nL 293.823245 60.335619 \nL 296.515537 78.533561 \nL 302.90973 122.548923 \nL 304.92895 134.79656 \nL 306.611633 143.817272 \nL 307.95778 150.095722 \nL 309.303924 155.432102 \nL 310.650071 159.742256 \nL 311.65968 162.25987 \nL 312.66929 164.139306 \nL 313.342363 165.02924 \nL 314.015435 165.624484 \nL 314.688508 165.922694 \nL 315.361582 165.922694 \nL 316.034654 165.624484 \nL 316.707727 165.02924 \nL 317.380799 164.13931 \nL 318.053872 162.958209 \nL 319.063484 160.651103 \nL 320.073093 157.720094 \nL 321.082702 154.191196 \nL 322.42885 148.610796 \nL 323.774995 142.111749 \nL 325.457676 132.853516 \nL 327.476898 120.384358 \nL 330.169191 102.186414 \nL 336.563383 58.171073 \nL 338.5826 45.923449 \nL 340.265285 36.90271 \nL 341.61143 30.624287 \nL 342.957579 25.287884 \nL 344.303724 20.977748 \nL 345.313333 18.460126 \nL 346.322941 16.58069 \nL 346.996014 15.69076 \nL 347.669086 15.095521 \nL 348.342162 14.797306 \nL 348.342162 14.797306 \n\" clip-path=\"url(#pc5d08e8c14)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"line2d_36\">\n    <path d=\"M 230.890914 90.359999 \nL 315.025046 165.96 \n\" clip-path=\"url(#pc5d08e8c14)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n   </g>\n   <g id=\"patch_8\">\n    <path d=\"M 207.350184 173.52 \nL 207.350184 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_9\">\n    <path d=\"M 355.056066 173.52 \nL 355.056066 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_10\">\n    <path d=\"M 207.350184 173.52 \nL 355.056066 173.52 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_11\">\n    <path d=\"M 207.350184 7.2 \nL 355.056066 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n  <g id=\"axes_3\">\n   <g id=\"patch_12\">\n    <path d=\"M 384.597243 173.52 \nL 532.303125 173.52 \nL 532.303125 7.2 \nL 384.597243 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g id=\"matplotlib.axis_5\">\n    <g id=\"xtick_7\">\n     <g id=\"line2d_37\">\n      <path d=\"M 391.311146 173.52 \nL 391.311146 7.2 \n\" clip-path=\"url(#p63da1048d9)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_38\">\n      <g>\n       <use xlink:href=\"#m45064b488f\" x=\"391.311146\" y=\"173.52\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_17\">\n      <!-- −2 -->\n      <g transform=\"translate(383.940053 188.118438)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-32\" x=\"83.789062\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_8\">\n     <g id=\"line2d_39\">\n      <path d=\"M 458.618452 173.52 \nL 458.618452 7.2 \n\" clip-path=\"url(#p63da1048d9)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_40\">\n      <g>\n       <use xlink:href=\"#m45064b488f\" x=\"458.618452\" y=\"173.52\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_18\">\n      <!-- 0 -->\n      <g transform=\"translate(455.437202 188.118438)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_9\">\n     <g id=\"line2d_41\">\n      <path d=\"M 525.925757 173.52 \nL 525.925757 7.2 \n\" clip-path=\"url(#p63da1048d9)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_42\">\n      <g>\n       <use xlink:href=\"#m45064b488f\" x=\"525.925757\" y=\"173.52\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_19\">\n      <!-- 2 -->\n      <g transform=\"translate(522.744507 188.118438)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-32\"/>\n      </g>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_6\">\n    <g id=\"ytick_11\">\n     <g id=\"line2d_43\">\n      <path d=\"M 384.597243 157.411453 \nL 532.303125 157.411453 \n\" clip-path=\"url(#p63da1048d9)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_44\">\n      <g>\n       <use xlink:href=\"#m43b016f915\" x=\"384.597243\" y=\"157.411453\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_20\">\n      <!-- 0.5 -->\n      <g transform=\"translate(361.694118 161.210672)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n       <use xlink:href=\"#DejaVuSans-35\" x=\"95.410156\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_12\">\n     <g id=\"line2d_45\">\n      <path d=\"M 384.597243 125.06014 \nL 532.303125 125.06014 \n\" clip-path=\"url(#p63da1048d9)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_46\">\n      <g>\n       <use xlink:href=\"#m43b016f915\" x=\"384.597243\" y=\"125.06014\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_21\">\n      <!-- 1.0 -->\n      <g transform=\"translate(361.694118 128.859359)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_13\">\n     <g id=\"line2d_47\">\n      <path d=\"M 384.597243 92.708827 \nL 532.303125 92.708827 \n\" clip-path=\"url(#p63da1048d9)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_48\">\n      <g>\n       <use xlink:href=\"#m43b016f915\" x=\"384.597243\" y=\"92.708827\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_22\">\n      <!-- 1.5 -->\n      <g transform=\"translate(361.694118 96.508046)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n       <use xlink:href=\"#DejaVuSans-35\" x=\"95.410156\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_14\">\n     <g id=\"line2d_49\">\n      <path d=\"M 384.597243 60.357514 \nL 532.303125 60.357514 \n\" clip-path=\"url(#p63da1048d9)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_50\">\n      <g>\n       <use xlink:href=\"#m43b016f915\" x=\"384.597243\" y=\"60.357514\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_23\">\n      <!-- 2.0 -->\n      <g transform=\"translate(361.694118 64.156733)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-32\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_15\">\n     <g id=\"line2d_51\">\n      <path d=\"M 384.597243 28.006201 \nL 532.303125 28.006201 \n\" clip-path=\"url(#p63da1048d9)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_52\">\n      <g>\n       <use xlink:href=\"#m43b016f915\" x=\"384.597243\" y=\"28.006201\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_24\">\n      <!-- 2.5 -->\n      <g transform=\"translate(361.694118 31.805419)scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-32\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n       <use xlink:href=\"#DejaVuSans-35\" x=\"95.410156\"/>\n      </g>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_53\">\n    <path d=\"M 391.311146 165.96 \nL 398.041875 163.456644 \nL 404.436075 160.835002 \nL 410.493726 158.110753 \nL 416.21485 155.302677 \nL 421.935969 152.24548 \nL 427.320555 149.120777 \nL 432.705138 145.735825 \nL 437.753187 142.306822 \nL 442.801235 138.610756 \nL 447.849283 134.626827 \nL 452.560795 130.629018 \nL 457.272306 126.341338 \nL 461.983817 121.742767 \nL 466.358792 117.174613 \nL 470.733766 112.29966 \nL 475.108741 107.097315 \nL 479.483717 101.545579 \nL 483.858692 95.620998 \nL 488.233666 89.298533 \nL 492.272105 83.086174 \nL 496.310543 76.489661 \nL 500.348982 69.485237 \nL 504.38742 62.04769 \nL 508.425859 54.15023 \nL 512.464297 45.764427 \nL 516.502732 36.860069 \nL 520.541174 27.405084 \nL 524.579609 17.365457 \nL 525.589221 14.76 \nL 525.589221 14.76 \n\" clip-path=\"url(#p63da1048d9)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"line2d_54\">\n    <path d=\"M 408.137973 159.199411 \nL 492.272105 83.086174 \n\" clip-path=\"url(#p63da1048d9)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n   </g>\n   <g id=\"patch_13\">\n    <path d=\"M 384.597243 173.52 \nL 384.597243 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_14\">\n    <path d=\"M 532.303125 173.52 \nL 532.303125 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_15\">\n    <path d=\"M 384.597243 173.52 \nL 532.303125 173.52 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_16\">\n    <path d=\"M 384.597243 7.2 \nL 532.303125 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"pba43b88faf\">\n   <rect x=\"30.103125\" y=\"7.2\" width=\"147.705882\" height=\"166.32\"/>\n  </clipPath>\n  <clipPath id=\"pc5d08e8c14\">\n   <rect x=\"207.350184\" y=\"7.2\" width=\"147.705882\" height=\"166.32\"/>\n  </clipPath>\n  <clipPath id=\"p63da1048d9\">\n   <rect x=\"384.597243\" y=\"7.2\" width=\"147.705882\" height=\"166.32\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "f = lambda x: 0.5 * x**2  # 凸函数\n",
    "g = lambda x: torch.cos(np.pi * x)  # 非凸函数\n",
    "h = lambda x: torch.exp(0.5 * x)  # 凸函数\n",
    "\n",
    "x, segment = torch.arange(-2, 2, 0.01), torch.tensor([-1.5, 1])\n",
    "d2l.use_svg_display()\n",
    "_, axes = d2l.plt.subplots(1, 3, figsize=(9, 3))\n",
    "for ax, func in zip(axes, [f, g, h]):\n",
    "    d2l.plot([x, segment], [func(x), func(segment)], axes=ax)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 11.2.1.3. 詹森不等式"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "#### $ \\sum_i \\alpha_i f(x_i)  \\geq f\\left(\\sum_i \\alpha_i x_i\\right) \\text{ and } E_X[f(X)] \\geq f\\left(E_X[X]\\right), $"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
